import Vue from 'vue'
// 过滤器-采集值状态
Vue.filter('collectionValueFilter', function (val) {
  switch (val) {
    case '正常':
      val = 'state-normal'

      break
    case '异常':
      val = 'state-abnormal'

      break
    case '撤防':
      val = 'state-abnormal'

      break
    case '自动':
      val = 'state-auto'

      break
    case '布防':
      val = 'state-auto'

      break
    case '未巡检':
      val = 'state-abnormal'

      break
    case '已巡检':
      val = 'state-normal'

      break

    default:
      val = 'state-auto'
      break
  }
  return val
})

// 过滤器-气象信息的图标class
Vue.filter('typeFilter', function (val) {
  switch (val) {
    // 风速
    case '040201':
      val = 'iconfengsu'

      break
      // 风向
    case '040202':
      val = 'iconfengxiang-copy-copy'

      break
      // 温度
    case '040203':
      val = 'iconwendu'

      break
      // 湿度
    case '040204':
      val = 'iconIOTtubiao_huabanfuben'

      break
      // 雨量
    case '040206':
      val = 'iconyuliang'

      break
      // 风力
    case '040207':
      val = 'iconfengli'

      break

    default:
      val = ''
      break
  }
  return val
})

// 过滤器-气象信息的名称
Vue.filter('typeNameFilter', function (val) {
  switch (val) {
    // 风速
    case '040201':
      val = '风速'

      break
      // 风向
    case '040202':
      val = '风向'

      break
      // 温度
    case '040203':
      val = '温度'

      break
      // 湿度
    case '040204':
      val = '湿度'

      break
      // 雨量
    case '040206':
      val = '雨量'

      break

    default:
      val = ''
      break
  }
  return val
})
Vue.filter('time', function (time) {
  const dateTime = new Date(time);
  const year = dateTime.getFullYear();
  const month = dateTime.getMonth() + 1;
  const data = dateTime.getDate() + 1;
  const hour = dateTime.getHours();
  const minute = dateTime.getMinutes();
  const second = dateTime.getSeconds();

  function addZero(v) {
    return v < 10 ? '0' + v : v
  }
  return `${year}-${addZero(month)}-${addZero(data)} ${addZero(hour)}:${addZero(minute)}:${addZero(second)}`
})

// 气象信息处理
/*
  k:{
    "pointerId": "6010#040201#00024",
    "stationId": "8a1ea5c64bdebad1014bdebc55c80003",
    "stationName": "220Kv东门变电站",
    "type": "",
    "typeName": "",
    "unit": "m/s",
    "value": 30
  }

  before--------------item:{}
  after----------------item:{
    stationId:'',
    stationName:''
    Temperature: "6.2s℃", //温度
    Humidity: "77.10%", //湿度
    windSpe: "16m/s", //风速
    wind: "二级", //风力
    directionTheWind: "东北(44')", //风向
    rainfall: "7.00mm", //雨量
    ...
  }
*/
function typeName(item, k, option = {
  stationId: 'stationId',
  stationName: 'stationName',
  value: 'value',
  type: 'type',
  unit: 'unit'
}) {
  item.stationId = k.stationId
  item.stationName = k.stationName

  if (k[option.type] === "040201") {
    item.windSpe = k[option.value] || 0;
    item.windSpeUnit = k[option.unit] || '';
    item.wind = feng(k[option.value]) || '';
  }
  if (k[option.type] === "040202") {
    item.directionTheWind = k[option.value] || 0;
    item.directionTheWindUnit = k[option.unit] || '';

  }
  if (k[option.type] === "040203") {
    item.Temperature = k[option.value] || 0;
    item.TemperatureUnit = k[option.unit] || '';
  }
  if (k[option.type] === "040204") {
    item.Humidity = k[option.value] || 0;
    item.HumidityUnit = k[option.unit] || '';
  }
  if (k[option.type] === "040206") {
    item.rainfall = k[option.value] || 0;
    item.rainfallUnit = k[option.unit] || '';
  }
  if (k[option.type] === "040207") {
    item.pressure = k[option.value] || 0;
    item.pressureUnit = k[option.unit] || '';
  }
}

// 风速值——>风力等级
function feng(val) {
  let string = "";
  if (val >= 0 && val <= 0.2) {
    string = "零级";
  } else if (val >= 0.3 && val <= 1.5) {
    string = "一级";
  } else if (val >= 1.6 && val <= 3.3) {
    string = "二级";
  } else if (val >= 3.4 && val <= 5.4) {
    string = "三级";
  } else if (val >= 5.5 && val <= 7.9) {
    string = "四级";
  } else if (val >= 8.0 && val <= 10.7) {
    string = "五级";
  } else if (val >= 10.8 && val <= 13.8) {
    string = "六级";
  } else if (val >= 13.9 && val <= 17.1) {
    string = "七级";
  } else if (val >= 17.2 && val <= 20.7) {
    string = "八级";
  } else if (val >= 20.8 && val <= 24.4) {
    string = "九级";
  } else if (val >= 24.5 && val <= 28.4) {
    string = "十级";
  } else if (val >= 28.5 && val <= 32.3) {
    string = "十一级";
  } else if (val >= 32.7 && val <= 36.9) {
    string = "十二级";
  }
  return string;
}

// data——>obj
/*before:
[
  {
    stationId:'stationIdxxx',
    aaa:'xxx'
  }
]
after:
{
  'stationIdxxx':{
    aaa:'xxx'
  }
}
*/
function dataToRes(arr) {
  let obj = {};
  arr.forEach((k, j) => {
    let item = (obj[k.stationId] = obj[k.stationId] || {});
    typeName(item, k)
  });
  return obj
}

// 过滤器-风力
Vue.filter('fengliFilter', feng)

export default {
  feng,
  typeName,
  dataToRes
}


// 过滤器-在线监测- 历史数据弹框 state状态
Vue.filter('zxjcState', function (val) {
  switch (val) {
    case '0':
      val = '注意'

      break
    case '1':
      val = '告警'

      break
    case '2':
      val = '告警'

      break
    case '3':
      val = '告警'

      break
    case '4':
      val = '告警'
      break
    case '5':
      val = '正常'
      break
    default:
      val = ''
      break
  }
  return val


})
//   '0':'注意告警',
//   '1':'越限告警' ,
//   '2':'变位告警' ,
//   '3':'闭合告警' ,
//   '4':'断开告警' ,
//   '5':'不告警'
// 过滤器-在线监测- state状态
Vue.filter('zxjcBataleState', function (val) {
  switch (val) {
    case '0':
      val = '注意'

      break
    case '1':
      val = '告警'

      break
    case '2':
      val = '告警'

      break
    case '3':
      val = '告警'

      break
    case '4':
      val = '告警'
      break
    case '5':
      val = '正常'
      break
    default:
      val = ''
      break
  }
  return val


})
